package com.pacs.service;

import java.util.UUID;

import com.pacs.model.UserWechats;
import com.pacs.model.Users;

public class AccountService {
	
	/**
	 * 创建微信用户
	 * @param openid
	 */
	public Users createWxUser(String openid) {
		UserWechats userWechats = new UserWechats();
		userWechats.setOpenid(openid);
		userWechats.setUid(creatId());
		userWechats.setSubscribeStstus(1);
		userWechats.setCtime(getCurrentTimeInt());
		userWechats.save();
		Users users = new Users();
		users.setId(userWechats.getUid());
		users.setCtime(getCurrentTimeInt());
		users.save();
		return users;
	}
	
	private Integer getCurrentTimeInt() {
		return (int) (System.currentTimeMillis() / 1000);
	}
	
	private String creatId() {
		return UUID.randomUUID().toString().replace("-", "");
	}
}
